package com.youbug.system.controller;


import com.youbug.system.entity.Dictionary;
import com.youbug.system.service.IDictionaryService;
import com.youbug.common.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2023-02-12
 */
@RestController
@RequestMapping("/useDic")
public class UseDicController {

    @Autowired
    private IDictionaryService dictionaryService;

    @GetMapping("/getDicItems/{typeCode}")
    public R<List<Dictionary>> getDicTypes(@PathVariable String typeCode){

        List<Dictionary> list = dictionaryService.listByTypeCode(typeCode);

        return R.ok(list);
    }

    
    @GetMapping("/dicCodeTrans/{typeCode}/{itemCode}")
    public R<String> dicCodeTrans(@PathVariable String typeCode, @PathVariable String itemCode){

        Dictionary dictionary = dictionaryService.getOneByTypeAndCode(typeCode, itemCode);

        return R.ok(dictionary == null ? "-" : dictionary.getValue());
    }
}

